package com.yhn.init.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.init.common.BaseResponse;
import com.yhn.init.common.DeleteRequest;
import com.yhn.init.common.ResultUtils;
import com.yhn.init.model.dto.installationDetails.AfterInstallationRequest;
import com.yhn.init.model.dto.installationDetails.InstallationDetailsQueryRequest;
import com.yhn.init.model.dto.installationDetails.InstallationDetailsUpdateRequest;
import com.yhn.init.model.vo.InstallationDetailsVO;
import com.yhn.init.service.InstallationDetailsService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 安装师信息
 *
 * @author yhnyhn123
 * @email 2236751002@qq.com
 * @date 2024-03-08 20:36:42
 */
@RestController
@RequestMapping("/installationdetails")
public class InstallationDetailsController {

    @Resource
    private InstallationDetailsService installationDetailsService;

    /**
     * 列表,分页
     */
    @GetMapping("/list")
    //@SaCheckPermissions("furniture/installationdetails/list")
    public BaseResponse<Page<InstallationDetailsVO>> listByPage(@RequestBody InstallationDetailsQueryRequest installationDetailsQueryRequest) {
        Page<InstallationDetailsVO> page = installationDetailsService.queryPage(installationDetailsQueryRequest);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    //@SaCheckPermissions("furniture/installationdetails/info")
    public BaseResponse<InstallationDetailsVO> getInfoById(@PathVariable("id") Long id) {
        InstallationDetailsVO installationDetails = installationDetailsService.getInfoById(id);

        return ResultUtils.success(installationDetails);
    }


    /**
     * 保存
     */
    @PostMapping("/save")
    // @SaCheckPermissions("furniture/installationdetails/save")
    public BaseResponse<Long> save(@RequestBody AfterInstallationRequest installationDetailsAddRequest) {
        Long newId = installationDetailsService.saveInstallationDetails(installationDetailsAddRequest);

        return ResultUtils.success(newId);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@SaCheckPermissions("furniture/installationdetails/update")
    public BaseResponse<Boolean> update(@RequestBody InstallationDetailsUpdateRequest installationDetailsUpdateRequest) {
        boolean result = installationDetailsService.updateInstallationDetails(installationDetailsUpdateRequest);

        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    //@SaCheckPermissions("furniture/installationdetails/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        boolean result = installationDetailsService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    //@SaCheckPermissions("furniture/installationdetails/delete")
    public BaseResponse<Boolean> deleteBatch(@RequestBody Long[] ids) {
        boolean result = installationDetailsService.deleteBatchByIds(ids);
        return ResultUtils.success(result);
    }

    @PostMapping("/upload")
    @SaCheckPermission(value = {"/furniture/installation/add", "root"}, mode = SaMode.OR)
    public BaseResponse<InstallationDetailsVO> afterInstallation(@RequestPart("productImg") MultipartFile productImg,
                                                                 @RequestPart("customerPhoto") MultipartFile customerPhoto,
                                                                 @RequestPart("customerSignature") MultipartFile customerSignature,
                                                                 @Valid AfterInstallationRequest afterInstallationRequest) {
        return ResultUtils.success(installationDetailsService.
                afterInstallation(productImg, customerPhoto, customerSignature, afterInstallationRequest));
    }
}
